<template>
  <div class="app-container">
    <div class="mb20">
      <div class="data-container">
        <div class="data-item">
          <div class="data-title">合同总数：</div>
          <div class="data-content">
            {{ statistics.contractTotalNumber || 0 }}
          </div>
        </div>
        <div class="data-item">
          <div class="data-title">使用数量：</div>
          <div class="data-content">
            {{ statistics.contractUsedNumber || 0 }}
          </div>
        </div>
        <div class="data-item">
          <div class="data-title">剩余数量：</div>
          <div class="data-content">
            {{ statistics.contractLeftNumber || 0 }}
          </div>
        </div>
      </div>
    </div>
    <div class="mb20">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </div>

    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="购买时间" prop="dateRange">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        @change="dateRangeChange"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="类型" prop="visaRecordType">
        <el-select
          v-model="queryParams.visaRecordType"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="dict in visaRecordType"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          plain-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleAdd"-->
    <!--          v-hasPermi="['enterprise:contract:add']"-->
    <!--        >新增-->
    <!--        </el-button-->
    <!--        >-->
    <!--      </el-col>-->
    <!--      <right-toolbar-->
    <!--        :showSearch.sync="showSearch"-->
    <!--        @queryTable="getList"-->
    <!--      ></right-toolbar>-->
    <!--    </el-row>-->
    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="购买时间" prop="createTime" />
      <el-table-column label="类型" prop="visaRecordType">
        <template slot-scope="scope">
          {{ scope.row.visaRecordType === '0' ? '增加' : scope.row.visaRecordType === '1' ? '扣减' : '' }}
        </template>
      </el-table-column>
      <el-table-column label="数量" prop="visaNum" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getElectronicVisa, listElectronicVisaRecord } from '@/api/contract/electronicVisaRecord'

export default {
  name: 'contract',
  dicts: [],
  components: {},
  data() {
    return {
      //统计数据
      statistics: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      list: [],
      // 弹出层标题
      title: '',
      //表格行id
      id: undefined,
      //是否详情页
      isDetail: false,
      // 是否显示弹出层
      open: false,
      // 当前选择
      current: '0',
      // 日期范围
      dateRange: [],
      // 是否显示新建合同弹窗
      addDialogVisible: false,
      // 是否显示合同详情弹窗
      detailDialogVisible: false,
      // 记录类型
      visaRecordType: [
        {
          value: '0',
          label: '增加'
        },
        {
          value: '1',
          label: '扣减'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        visaRecordType: undefined, //记录类型:0.增加;1.扣减
        startTime: '', //入住时间
        endTime: '', //入住时间
        dateRange: [] //入住时间
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  computed: {},
  created() {
    this.getList()
    this.getElectronicVisaData()
  },
  methods: {
    //关闭回调
    dialogClose() {
      this.openCheckOut = false
    },
    /** 日期范围变化 */
    dateRangeChange(val) {
      if (val) {
        this.queryParams.startTime = val[0]
        this.queryParams.endTime = val[1]
      } else {
        this.queryParams.startTime = ''
        this.queryParams.endTime = ''
      }

    },
    /** 查询列表 */
    getList() {
      this.loading = true
      listElectronicVisaRecord(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },

    /** 合同数据 */
    getElectronicVisaData(){
      getElectronicVisa().then(response => {
        this.statistics = response.data
      })
    },
    // 表单重置
    reset() {
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.contractId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.addDialogVisible = true
      this.title = '新增业主合同'
    },
    handleDetail(row) {
      this.detailDialogVisible = true
      this.title = '详情'
      this.id = row.contractId
      this.isDetail = true
    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  font-size: 16px;
  font-weight: bold;
  color: #666;
}

.total {
  font-size: 24px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}

.left-border {
  border-left: 1px solid #999;
}

.right-border {
  border-right: 1px solid #999;
}

.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;

  span {
    color: #565c5f;
  }

  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}

.QR-code {
  padding: 30px;
  width: 100%;
  display: flex;
  justify-content: center
}

.data-container {
  display: grid;
  grid-template-columns: repeat(3, 200px  );
  grid-gap: 20px;
  margin-top: 20px;

  .data-item {
    border: 1px solid #DCDFE5;
    padding: 10px;
    border-radius: 5px;

    .data-title {
      font-size: 16px;
      font-weight: bold;
      color: #333;
    }

    .data-content {
      font-size: 36px;
      font-weight: bold;
      color: #666;
    }
  }
}
</style>
